<template>
  <div class="row">
      <div class="col-4" v-for="column in columnList" :key="column.id">
        <div class="card" >
        <img :src="column.avatar"  class="card-img-top"  :alt="column.title"/>
        <div class="card-body">
          <h5 class="card-title">{{column.title}}</h5>
          <p class="card-text">{{column.description}}</p>
          <a href="#" class="btn btn-primary">进入专栏</a>
        </div>
      </div>
      </div>
  </div>
</template>

<script lang='ts'>
import { computed, defineComponent, PropType } from 'vue'

export interface ColumnProps{
  id:number;
  title:string;
  avatar?:string;
  description:string;
}

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(item => {
        if (!item.avatar) {
          item.avatar = require('@/assets/empty.png')
        }
        return item
      })
    })
    return {
      columnList
    }
  }
})
</script>

<style lang='stylus' scoped>
</style>
